﻿<UserControl x:Class="ColorChooserX2.Views.ChooserX2"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:c="clr-namespace:ColorChooserX2.Views.Components"
             xmlns:v="clr-namespace:ColorChooserX2.Views"
             xmlns:vm="clr-namespace:ColorChooserX2.ViewModels"
             xmlns:conv="clr-namespace:ColorChooserX2.Views.Converter"
             mc:Ignorable="d" 
             d:DataContext="{d:DesignInstance Type=vm:HSVFieldViewModel, IsDesignTimeCreatable=True}"
             d:DesignHeight="300" d:DesignWidth="300">
    <Border Style="{DynamicResource ColorChooserControlBorderStyle}">
    <Grid>
        <Grid.Resources>
            <conv:HueToColorConverter x:Key="HueToColorConverter" />
            <conv:ValueToColorConverter x:Key="ValueToColorConverter" />
            <conv:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
            <conv:ColumnWidthConverter x:Key="ColumnWidthConverter" />
        </Grid.Resources>
        <ContentPresenter Content="{Binding}" Name="content" >
            <ContentPresenter.ContentTemplateSelector>
                <v:ChooserX2TemplateSelector>
                    <v:ChooserX2TemplateSelector.RGBFieldTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="45" />
                                    <ColumnDefinition Width="{Binding EnableAlphaChannel,Converter={StaticResource ColumnWidthConverter},ConverterParameter=45}" />
                                </Grid.ColumnDefinitions>
                                <c:HSVColorField DataContext="{Binding}"  Grid.Column="0"/>
                                <c:SpectrumSlider Margin="0,8,0,8" VerticalAlignment="Stretch" HorizontalAlignment="Center" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type Grid}}, Path=DataContext.Saturation,Mode=TwoWay}" Grid.Column="1">
                                    <c:SpectrumSlider.BarBrush>
                                        <LinearGradientBrush>
                                            <GradientStop Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type Grid}}, Path=DataContext.HSV, Converter={StaticResource HueToColorConverter}}" Offset="0" />
                                            <GradientStop Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type Grid}}, Path=DataContext.Value, Converter={StaticResource ValueToColorConverter}}" Offset="1" />
                                        </LinearGradientBrush>
                                    </c:SpectrumSlider.BarBrush>
                                </c:SpectrumSlider>
                                <c:SpectrumSlider Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type Grid}}, Path=DataContext.EnableAlphaChannel,Converter={StaticResource BoolToVisibilityConverter}}" Margin="0,8,0,8" VerticalAlignment="Stretch" HorizontalAlignment="Center" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type Grid}}, Path=DataContext.NormalizedAlpha,Mode=TwoWay}" Grid.Column="2">
                                    <c:SpectrumSlider.Bar2Brush>
                                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                            <GradientStop Color="White" Offset="0" />
                                            <GradientStop Color="Transparent" Offset="1" />
                                        </LinearGradientBrush>
                                    </c:SpectrumSlider.Bar2Brush>
                                        <c:SpectrumSlider.BarBrush>
                                        <DrawingBrush Viewport="0,0,0.5,0.05" TileMode="Tile">
                                            <DrawingBrush.Drawing>
                                                <DrawingGroup>
                                                    <GeometryDrawing Brush="White">
                                                        <GeometryDrawing.Geometry>
                                                            <RectangleGeometry Rect="0,0,100,100"  />
                                                        </GeometryDrawing.Geometry>
                                                    </GeometryDrawing>
                                                    <GeometryDrawing >
                                                        <GeometryDrawing.Geometry>
                                                            <GeometryGroup>
                                                                <RectangleGeometry Rect="0,0,50,50" />
                                                                <RectangleGeometry Rect="50,50,50,50" />
                                                            </GeometryGroup>
                                                        </GeometryDrawing.Geometry>
                                                        <GeometryDrawing.Brush >
                                                            <LinearGradientBrush>
                                                                <GradientStop Offset="0.0" Color="Black" />
                                                                <GradientStop Offset="1.0" Color="Gray" />
                                                            </LinearGradientBrush>
                                                        </GeometryDrawing.Brush>
                                                    </GeometryDrawing>
                                                </DrawingGroup>
                                            </DrawingBrush.Drawing>
                                        </DrawingBrush>
                                    </c:SpectrumSlider.BarBrush>
                                </c:SpectrumSlider>
                            </Grid>
                        </DataTemplate>
                    </v:ChooserX2TemplateSelector.RGBFieldTemplate>
                </v:ChooserX2TemplateSelector>
            </ContentPresenter.ContentTemplateSelector>
        </ContentPresenter>
    </Grid>
    </Border>
</UserControl>
